package com.zsc.wxm.ysh.anjo.utils;

import cn.hutool.http.HttpStatus;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zsc.wxm.ysh.anjo.result.Result;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 描述： 响应工具类
 *
 * @author playmaker
 * @since 2021/2/6 15:44
 */
@Slf4j
public class ResponseUtil {

    public static void response(HttpServletResponse response, Result r) {
        ObjectMapper mapper = new ObjectMapper();
        response.setStatus(HttpStatus.HTTP_OK);
        response.setContentType("application/json;charset=UTF-8");
        try {
            mapper.writeValue(response.getWriter(), r);
        } catch (IOException e) {
            log.error("ResponseUtil---->response 返回信息异常{}", e.getMessage());
        }
    }
}
